#include "movefreevmarksettingview.h"
#include "ui_movefreevmarksettingview.h"
#include "movefreeinstructionview.h"
#include "../../programView/programview.h"

MoveFreeVmarkSettingView::MoveFreeVmarkSettingView(int styleId,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MoveFreeVmarkSettingView)
{
    ui->setupUi(this);
    initialDisplayStyle(styleId);
}

void MoveFreeVmarkSettingView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->forward_Btn->setGeometry(10,350,70,40);
        ui->save_Btn->setGeometry(360,350,70,40);
        break;
    default:
        break;
    }
}

void MoveFreeVmarkSettingView::getInput()
{
    // 获取界面输入
    int currentRowIndex = ui->VMark_ComBox->currentIndex();
    // 普通点
    if(currentRowIndex == 0)
    {
        pointType = EM_MOVE_FREE_DP;
        typeIndex = 0;
    }
    // 二维码点
    else if(currentRowIndex == 1)
    {
        pointType = EM_MOVE_FREE_QR;
        typeIndex = ui->TypeIndex_ComBox->currentIndex() + 1;
    }
    // VMark点
    else if(currentRowIndex == 2)
    {
        pointType = EM_MOVE_FREE_VMARK;
        // VMark点位选项从第三刚开始
        typeIndex = ui->TypeIndex_ComBox->currentIndex() + 1;
    }
    else if(currentRowIndex == 3)
    {
        pointType = EM_MOVE_FREE_CU1;
        typeIndex = 0;
    }

    jmpLbValue = ui->LBL_Edit->text();
    laserTypeNum = ui->Laser_Type_ComBox->currentIndex();

    int pathStratetyIndex=ui->comBox_pathStrategy->currentIndex();
    if(pathStratetyIndex == 0)
    {
        pathControlStrategy = E_PATH_CONTROL_STRATEGY_DIFFERENTIAL;
    }
    else if(pathStratetyIndex == 1)
    {
        pathControlStrategy = E_PATH_CONTROL_STRATEGY_MCCRUM;
    }
}

void MoveFreeVmarkSettingView::updateView()
{


    // DP点
    if(pointType == EM_MOVE_FREE_DP)
    {
        ui->VMark_ComBox->setCurrentIndex(0);
        ui->TypeIndex_ComBox->hide();
        ui->TypeIndex_Label->hide();
    }
    else if(pointType == EM_MOVE_FREE_CU1)
    {
        ui->VMark_ComBox->setCurrentIndex(3);
        ui->TypeIndex_ComBox->hide();
        ui->TypeIndex_Label->hide();
    }
    else if(pointType == EM_MOVE_FREE_QR)
    {
        ui->VMark_ComBox->setCurrentIndex(1);
        ui->TypeIndex_ComBox->show();
        ui->TypeIndex_Label->show();
        ui->TypeIndex_ComBox->setCurrentIndex(typeIndex -1);
    }
    else if(pointType == EM_MOVE_FREE_VMARK)
    {
        ui->VMark_ComBox->setCurrentIndex(2);
        ui->TypeIndex_ComBox->show();
        ui->TypeIndex_Label->show();
        ui->TypeIndex_ComBox->setCurrentIndex(typeIndex-1);
    }

    ui->LBL_Edit->setText(jmpLbValue);
    ui->Laser_Type_ComBox->setCurrentIndex(laserTypeNum);

    if(pathControlStrategy == E_PATH_CONTROL_STRATEGY_DIFFERENTIAL)
    {
        ui->comBox_pathStrategy->setCurrentIndex(0);
    }
    else if(pathControlStrategy == E_PATH_CONTROL_STRATEGY_MCCRUM)
    {
        ui->comBox_pathStrategy->setCurrentIndex(1);
    }
    else
    {
        ui->comBox_pathStrategy->setCurrentIndex(0);
    }
}

void MoveFreeVmarkSettingView::changeLanguage()
{
    ui->retranslateUi(this);
}

void MoveFreeVmarkSettingView::on_save_Btn_clicked()
{
    // 获取界面输入数据
    // 发送指令属性编辑完成信号
    emit finishedEditInstruction();
    // 关闭当前界面
    this->close();
    // 更新显示指令程序列表界面
    programView->instructionListFlag = 0;
    programView->editInstructionViewShowOrHide();
}

void MoveFreeVmarkSettingView::on_forward_Btn_clicked()
{
    this->close();
    moveFreeInstructionView->show();
}

void MoveFreeVmarkSettingView::on_VMark_ComBox_currentIndexChanged(int index)
{
    if(index == 0)
    {
        ui->TypeIndex_ComBox->hide();
        ui->TypeIndex_Label->hide();
        pointType = EM_MOVE_FREE_DP;
    }
    else if(index == 1)
    {
        ui->TypeIndex_ComBox->show();
        ui->TypeIndex_Label->show();
        pointType = EM_MOVE_FREE_QR;
    }
    else if(index == 2)
    {
        ui->TypeIndex_ComBox->show();
        ui->TypeIndex_Label->show();
        pointType = EM_MOVE_FREE_VMARK;
    }
    else if(index == 3)
    {
        ui->TypeIndex_ComBox->hide();
        ui->TypeIndex_Label->hide();
        pointType = EM_MOVE_FREE_CU1;
    }
}
